package com.qf.j2112.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class IpUtil {

    //获取访问者ip地址
    public static String getRemoteIp() {
        HttpServletRequest request = null;
        try {
            request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
        } catch (Exception e) {
            System.out.println("Can not get current IP.");
        }
        return request.getRemoteAddr();
    }

}
